package entity

import (
	"fmt"

	"shqsoft.cn/pasnj/base"

	"github.com/jinzhu/gorm"
)

//CswhJJZZ 经济增长值
type CswhJJZZ struct {
	ID           int     `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	KHYF         string  `gorm:"column:KHYF"`
	JYDW         string  `gorm:"column:JYDW"`
	OrganID      int     `gorm:"column:OrganID"`
	DGJJZJZ      float64 `gorm:"column:DGJJZJZ"`
	LSJJZJZ      float64 `gorm:"column:LSJJZJZ"`
	JJZJZHJ      float64 `gorm:"column:JJZJZHJ"`
	JSJJTZHJJZJZ float64 `gorm:"column:JSJJTZHJJZJZ"`
}

//TableName 经济增长值
func (CswhJJZZ) TableName() string {
	return "T_JHCW_JXFP_JJZJZ"

}

//CswhJJZZEF 返回结构体
func CswhJJZZEF() base.EntityFunc {
	return func() interface{} {
		entity := CswhJJZZ{}
		return &entity
	}
}

//CswhJJZZESF 返回结构体数组
func CswhJJZZESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CswhJJZZ
		return &entities
	}
}

//BeforeSave 保存前的触发器
func (i *CswhJJZZ) BeforeSave(tx *gorm.DB) (err error) {
	sqlEx := "select dbo.GetBackDATE()"
	row := tx.Raw(sqlEx).Row()

	var organid int
	sqlEx = "select ID  from T_Organization  where OrganName=?"
	row = tx.Raw(sqlEx, i.JYDW).Row()
	err = row.Scan(&organid)

	if organid == 0 {
		return fmt.Errorf("经营单位:%s在系统中没有找到！", i.JYDW)
	}
	return

}

func init() {
	base.DaoPoolObj.Put("CswhJJZZ", base.NewDefaultDao(CswhJJZZEF(), CswhJJZZESF(), nil))

}
